package com.stylefeng.guns.modular.channel_manage.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.channel_manage.model.ChannelInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.channel_manage.service.IChannelInfoService;

import java.util.Date;

/**
 * 渠道管理控制器
 *
 * @author fengshuonan
 * @Date 2020-06-26 11:53:46
 */
@Controller
@RequestMapping("/channelInfo")
public class ChannelInfoController extends BaseController {

    private String PREFIX = "/channel_manage/channelInfo/";

    @Autowired
    private IChannelInfoService channelInfoService;

    /**
     * 跳转到渠道管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "channelInfo.html";
    }

    /**
     * 跳转到添加渠道管理
     */
    @RequestMapping("/channelInfo_add")
    public String channelInfoAdd() {
        return PREFIX + "channelInfo_add.html";
    }

    /**
     * 获取渠道管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list() {
        return channelInfoService.channelPromoteList();
    }

    /**
     * 新增渠道管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(@RequestParam("channelName") String channelName) {
        channelInfoService.addChannel(channelName);
        return SUCCESS_TIP;
    }

    /**
     * 删除渠道管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam("channelId") Integer channelInfoId) {
        ChannelInfo channelInfo = channelInfoService.selectById(channelInfoId);
        channelInfo.setDeleteTime(new Date());
        channelInfoService.updateById(channelInfo);
        return SUCCESS_TIP;
    }

}
